<template>
    <div class="app-container content-wrapper">
        <el-row :gutter="20">
            <el-col :span="orgSpan" v-show="visibleShowOrg">
                <el-row class="margin-bottom-10">
                    <el-col>
                        <el-card class="box-card" :body-style="{ padding: '0px' }">
                            <div class="card-header clearfix">
                                <span><i class="el-icon-mars-department margin-right-5"></i> 公司</span>
                            </div>
                            <el-tree :data="dataCompany" node-key="id" ref="treeCompany"
                                     v-loading="loadingCompany"
                                     highlight-current
                                     :check-strictly="true"
                                     :default-expand-all="false"
                                     :props="defaultProps"
                                     @node-click="handleCompanyNodeClick"
                            ></el-tree>
                        </el-card>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col>
                        <el-card class="box-card" :body-style="{ padding: '0px' }">
                            <div class="card-header clearfix">
                                <span><i class="el-icon-mars-dept margin-right-5"></i> 部门</span>
                            </div>
                            <el-tree :data="dataDept" node-key="id" ref="treeDept"
                                     v-loading="loadingDept"
                                     highlight-current
                                     :check-strictly="true"
                                     :default-expand-all="false"
                                     :props="defaultProps"
                                     @node-click="handleDeptNodeClick"
                            ></el-tree>
                        </el-card>
                    </el-col>
                </el-row>
            </el-col>
            <el-col :span="userSpan">
                <div class="filter-container">
                    <el-form :model="listQuery" :inline="true" ref="filterForm" style="display: inline-block">
                        <el-form-item prop="account" class="filter-item">
                            <el-input v-model="listQuery.account" placeholder="账号" style="width: 150px;"></el-input>
                        </el-form-item>
                        <el-form-item prop="realName" class="filter-item">
                            <el-input v-model="listQuery.realName" placeholder="姓名" style="width: 150px;"></el-input>
                        </el-form-item>
                        <el-form-item prop="sex" class="filter-item">
                            <el-select v-model="listQuery.sex" placeholder="性别" clearable style="width: 100px">
                                <el-option
                                        v-for="item in sexOptions"
                                        :key="item.key"
                                        :label="item.label"
                                        :value="item.key">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="status" class="filter-item">
                            <el-select v-model="listQuery.status" placeholder="状态" style="width: 100px">
                                <el-option
                                        v-for="item in statusOptions"
                                        :key="item.key"
                                        :label="item.label"
                                        :value="item.key">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item prop="orderBy" class="filter-item">
                            <el-select v-model="listQuery.orderBy" placeholder="排序" style="width: 150px">
                                <el-option
                                        v-for="item in sortOptions"
                                        :key="item.key"
                                        :label="item.label"
                                        :value="item.key">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-button class="filter-item" type="primary" icon="search" @click="handleFilter">搜索</el-button>
                        <el-button class="filter-item" type="primary" icon="mars-reset" @click="handleResetFilter">重置</el-button>
                        <el-button class="filter-item" type="primary" icon="mars-filter" @click="handleVisibleShowOrg">机构筛选</el-button>
                        <el-button class="filter-item" type="primary" icon="plus" @click="handleCreate()">添加</el-button>
                        <el-dropdown class="filter-item margin-left-10" trigger="click" @command="command">
                            <el-button type="primary">
                                更多操作<i class="el-icon-caret-bottom el-icon--right"></i>
                            </el-button>
                            <el-dropdown-menu slot="dropdown" style="width: 200px;">
                                <el-dropdown-item command="ResetPassword">重置密码</el-dropdown-item>
                                <el-dropdown-item command="AddOrganization">加入机构</el-dropdown-item>
                                <el-dropdown-item command="AddRole">分配角色</el-dropdown-item>
                                <el-dropdown-item command="AddGroup">加入用户组</el-dropdown-item>
                                <el-dropdown-item command="SetStatusNormal" divided>设置状态：正常</el-dropdown-item>
                                <el-dropdown-item command="SetStatusForbidden">设置状态：禁用</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </el-form>
                </div>

                <el-table :data="list"
                          v-loading="listLoading"
                          element-loading-text="给我一点时间"
                          border
                          fit
                          highlight-current-row
                          @selection-change="handleSelectionChange"
                          style="width: 100%">

                    <el-table-column
                            type="selection"
                            width="55">
                    </el-table-column>

                    <el-table-column label="ID" width="65" align="center">
                        <template slot-scope="scope"> {{scope.row.id}} </template>
                    </el-table-column>

                    <el-table-column label="姓名" width="110px" align="center">
                        <template slot-scope="scope"> {{scope.row.realName}} </template>
                    </el-table-column>

                    <el-table-column label="性别" width="80px" align="center">
                        <template slot-scope="scope"> {{scope.row.sex | sexFilter}} </template>
                    </el-table-column>

                    <el-table-column label="账号" width="110px" align="center">
                        <template slot-scope="scope"> {{scope.row.account}} </template>
                    </el-table-column>

                    <el-table-column label="手机号码" width="130px" align="center">
                        <template slot-scope="scope"> {{scope.row.mobile}} </template>
                    </el-table-column>

                    <el-table-column label="邮件地址" min-width="200px" align="center" show-overflow-tooltip>
                        <template slot-scope="scope"> {{scope.row.email}} </template>
                    </el-table-column>

                    <el-table-column label="状态" align="center">
                        <template slot-scope="scope">
                            <el-tag :type="scope.row.status | statusTagFilter">{{scope.row.status | statusFilter}}</el-tag>
                        </template>
                    </el-table-column>

                    <el-table-column label="登录次数" min-width="" align="center">
                        <template slot-scope="scope"> {{scope.row.loginCount}} </template>
                    </el-table-column>

                    <el-table-column label="最后登录IP" width="110px" min-width="" align="center">
                        <template slot-scope="scope"> {{scope.row.lastLoginIp}} </template>
                    </el-table-column>

                    <el-table-column label="最后登录时间" width="170px" align="center">
                        <template slot-scope="scope"> {{scope.row.lastLoginTime }} </template>
                    </el-table-column>

                    <el-table-column label="创建时间" width="150px" align="center">
                        <template slot-scope="scope"> {{scope.row.ctime | parseTime('{y}-{m}-{d} {h}:{i}')}} </template>
                    </el-table-column>

                    <el-table-column label="操作" fixed="right" width="180px" align="center">
                        <template slot-scope="scope">
                            <el-button size="small" type="primary" icon="edit" @click="handleUpdate(scope.row)">编辑</el-button>

                            <el-button size="small" type="danger" icon="delete" @click="handleDelete(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>

                </el-table>

                <div v-show="!listLoading" class="pagination-container">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="listQuery.page"
                            :page-sizes="[10, 20, 30, 50]"
                            :page-size="listQuery.rows"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
                    </el-pagination>
                </div>

                <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" size="tiny" @close="handleCloseDialog">
                    <el-form :model="form" :rules="rules" ref="form" labelPosition="right" labelWidth="80px" style="width: 400px">
                        <el-form-item label="登录账号" prop="account">
                            <el-input v-model="form.account"></el-input>
                        </el-form-item>

                        <el-form-item label="姓名">
                            <el-input v-model="form.realName"></el-input>
                        </el-form-item>

                        <el-form-item label="性别">
                            <el-select v-model="form.sex" placeholder="性别" style="width: 100px">
                                <el-option
                                        v-for="item in sexOptions"
                                        :key="item.key"
                                        :label="item.label"
                                        :value="item.key"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="手机号码" prop="mobile">
                            <el-input v-model="form.mobile"></el-input>
                        </el-form-item>

                        <el-form-item label="邮件地址" prop="email">
                            <el-input v-model="form.email"></el-input>
                        </el-form-item>

                        <el-form-item label="账号状态">
                            <el-radio-group v-model="form.status">
                                <el-radio :label="1">正常</el-radio>
                                <el-radio :label="2">锁定</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取 消</el-button>
                        <el-button v-if="dialogStatus == 'create'" type="primary" @click="create">确 定</el-button>
                        <el-button v-else="" type="primary" @click="update">确 定</el-button>
                    </div>
                </el-dialog>

                <el-dialog title="加入到组" :visible.sync="dialogGroupVisible">
                    <div class="filter-container">
                        <el-form :model="listQueryGroup" :inline="true" style="display: inline-block">
                            <el-form-item prop="name" class="filter-item">
                                <el-input v-model="listQueryGroup.name" placeholder="组名称" style="width: 200px;"></el-input>
                            </el-form-item>
                            <el-button class="filter-item" type="primary" icon="search" @click="handleFilterGroup">搜索</el-button>
                        </el-form>
                    </div>
                    <el-table :data="listGroup"
                              v-loading="listLoadingGroup"
                              border
                              fit
                              highlight-current-row
                              style="width: 100%"
                              @row-click="selectGroup">
                        <el-table-column label="序号" width="65" align="center">
                            <template slot-scope="scope"> {{scope.row.id}} </template>
                        </el-table-column>

                        <el-table-column label="组名称" width="300px" align="center">
                            <template slot-scope="scope"> {{scope.row.name}} </template>
                        </el-table-column>

                        <el-table-column label="唯一标识" width="150px" align="center">
                            <template slot-scope="scope"> {{scope.row.identity}} </template>
                        </el-table-column>

                        <el-table-column label="备注" min-width="300px" align="center">
                            <template slot-scope="scope"> {{scope.row.remarks}} </template>
                        </el-table-column>
                    </el-table>
                    <div v-show="!listLoadingGroup" class="pagination-container">
                        <el-pagination
                                @size-change="handleSizeChangeGroup"
                                @current-change="handleCurrentChangeGroup"
                                :current-page="listQueryGroup.page"
                                :page-sizes="[10, 20, 30, 50]"
                                :page-size="listQueryGroup.rows"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="totalGroup">
                        </el-pagination>
                    </div>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogGroupVisible = false">取 消</el-button>
                        <el-button type="primary" @click="handelSaveAssignGroup">确 定</el-button>
                    </div>
                </el-dialog>

                <el-dialog title="分配角色" :visible.sync="dialogRoleVisible">
                    <div class="filter-container">
                        <el-form :model="listQueryRole" :inline="true" style="display: inline-block">
                            <el-form-item prop="name" class="filter-item">
                                <el-input v-model="listQueryRole.name" placeholder="角色名称" style="width: 200px;"></el-input>
                            </el-form-item>
                            <el-button class="filter-item" type="primary" icon="search" @click="handleFilterRole">搜索</el-button>
                        </el-form>
                    </div>
                    <el-table :data="listRole"
                              v-loading="listLoadingRole"
                              border
                              fit
                              highlight-current-row
                              style="width: 100%"
                              @row-click="selectRole">
                        <el-table-column label="序号" width="65" align="center">
                            <template slot-scope="scope"> {{scope.row.id}} </template>
                        </el-table-column>

                        <el-table-column label="组名称" width="300px" align="center">
                            <template slot-scope="scope"> {{scope.row.name}} </template>
                        </el-table-column>

                        <el-table-column label="唯一标识" width="150px" align="center">
                            <template slot-scope="scope"> {{scope.row.identity}} </template>
                        </el-table-column>

                        <el-table-column label="备注" min-width="300px" align="center">
                            <template slot-scope="scope"> {{scope.row.remarks}} </template>
                        </el-table-column>
                    </el-table>
                    <div v-show="!listLoadingRole" class="pagination-container">
                        <el-pagination
                                @size-change="handleSizeChangeRole"
                                @current-change="handleCurrentChangeRole"
                                :current-page="listQueryRole.page"
                                :page-sizes="[10, 20, 30, 50]"
                                :page-size="listQueryRole.rows"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="totalRole">
                        </el-pagination>
                    </div>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogRoleVisible = false">取 消</el-button>
                        <el-button type="primary" @click="handelSaveAssignRole">确 定</el-button>
                    </div>
                </el-dialog>

                <el-dialog title="加入到组织机构" :visible.sync="dialogOrganizationVisible">

                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-card class="box-card" :body-style="{ padding: '0px' }">
                                <div class="card-header clearfix">
                                    <span>公司</span>
                                </div>
                                <el-tree :data="dataCompany" node-key="id" ref="treeCompany"
                                         v-loading="loadingCompany"
                                         highlight-current
                                         :check-strictly="true"
                                         :default-expand-all="false"
                                         :props="defaultProps"
                                         @node-click="handleCompanyNodeClickDialog"
                                ></el-tree>
                            </el-card>
                        </el-col>
                        <el-col :span="12">
                            <el-card class="box-card" :body-style="{ padding: '0px' }">
                                <div class="card-header clearfix">
                                    <span>部门</span>
                                </div>
                                <el-tree :data="dataDept" node-key="id" ref="treeDept"
                                         v-loading="loadingDept"
                                         highlight-current
                                         :check-strictly="true"
                                         :default-expand-all="false"
                                         :props="defaultProps"
                                         @node-click="handleDeptNodeClickDialog"
                                ></el-tree>
                            </el-card>
                        </el-col>
                    </el-row>

                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogOrganizationVisible = false">取 消</el-button>
                        <el-button type="primary" @click="handelSaveAssignOrganization">确 定</el-button>
                    </div>
                </el-dialog>
            </el-col>
        </el-row>



    </div>
</template>

<script>
    import fetch from '@/utils/fetch'
    import {
        created,
        eleted,
        updated,
        fetchObject,
        fetchList,
        batchResetPassword,
        batchUpdateStatus,
        addUserToGroupAssign,
        addUserToOrganizationAssign,
        addUserToRoleAssign
    } from '@/api/upms/user'
    import { fetchTree as fetchCompanyTree } from '@/api/upms/company'
    import { fetchTree as fetchDeptTree } from '@/api/upms/dept'
    import { fetchList as fetchGroupList } from '@/api/upms/group'
    import { fetchList as fetchRoleList } from '@/api/upms/role'

    const sexOptions = [{label: '男', key: 1}, {label: '女', key: 2}, {label: '未知', key: 3}]
    const sortOptions = [{label: '按ID升序', key: 'id asc'}, {label: '按ID降序', key: 'id desc'}]
    const statusOptions = [{label: '正常', key: 1}, {label: '锁定', key: 2}]

    export default {
        name: 'user',
        data() {
            return {
                list: null,
                total: null,
                listLoading: true,
                dialogFormVisible: false,
                listQuery: {
                    page: 1,
                    rows: 10,
                    account: undefined,
                    realName: undefined,
                    status: undefined,
                    sex: undefined,
                    companyId: undefined,
                    departmentId: undefined,
                    orderBy: 'id asc'
                },

                listGroup: null,
                totalGroup: null,
                listLoadingGroup: true,
                dialogGroupVisible: false,
                selectGroupId: undefined,
                listQueryGroup: {
                    page: 1,
                    rows: 10,
                    name: undefined,
                    orderBy: 'ctime desc'
                },

                listRole: null,
                totalRole: null,
                listLoadingRole: true,
                dialogRoleVisible: false,
                selectRoleId: undefined,
                listQueryRole: {
                    page: 1,
                    rows: 10,
                    name: undefined,
                    orderBy: 'ctime desc'
                },

                dataCompany: [],
                loadingCompany: false,
                dataDept: [],
                loadingDept: false,
                formCompany: {
                    id: ''
                },
                formDept: {
                    id: ''
                },

                treeData: null,
                treeDataDialog: null,
                treeLoading: false,
                treeLoadingDialog: false,

                dialogOrganizationVisible: false,
                selectCompanyId: undefined,
                selectDeptId: undefined,
                visibleShowOrg: false,

                orgSpan: 6,
                userSpan: 24,
                multipleSelection: [],
                sexOptions,
                statusOptions,
                sortOptions,
                dialogStatus: '',
                textMap: {
                    update: '编辑',
                    create: '创建'
                },
                form: {
                    account: '',
                    realName: '',
                    sex: 1,
                    mobile: '',
                    email: '',
                    status: 1
                },
                rules: {
                    account: [
                        { required: true, message: '请输入活动名称', trigger: 'blur' },
                        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ],
                    mobile: [
                        { required: true, message: '请输入手机号码'},
                        { message: '手机必须为11位数字', pattern: /^1(3|4|5|7|8)\d{9}$/ }
                    ],
                    email: [
                        { required: true, message: '邮件地址不能为空', trigger: 'blur' },
                        { type: 'email', message: '邮件格式不正确', trigger: 'blur' }
                    ]
                },
                defaultProps: {
                    label: 'name',
                    children: 'children'
                },

            }
        },
        created() {
            this.getList()
        },
        filters: {
            sexFilter(sex) {
                const sexArray = ['男', '女', '未知']
                return sexArray[sex?--sex:'']
            },
            statusFilter(status) {
                const statusArray = ['正常', '锁定']
                return statusArray[status?--status:'']
            },
            statusTagFilter(status) {
                const statusArray = ['success', 'danger']
                return statusArray[status?--status:'']
            }
        },
        methods: {
            getList() {
                this.listLoading = true
                fetchList(this.listQuery).then(response => {
                    this.list = response.data.list
                    this.total = response.data.total
                    this.listLoading = false
                }).catch((error)=>{
                    console.log(error)
                    this.listLoading = false
                })
            },
            getDataCompany() {
                this.loadingCompany = true
                fetchCompanyTree().then(response => {
                    this.dataCompany = response.data
                    this.loadingCompany = false
                }).catch((error)=>{
                    console.log(error)
                    this.loadingCompany = false
                })
            },
            getDataDept(companyId) {
                this.loadingDept = true
                fetchDeptTree({companyId: companyId}).then(response => {
                    this.dataDept = response.data
                    this.loadingDept = false
                }).catch((error)=>{
                    console.log(error)
                    this.loadingDept = false
                })
            },
            getGroupList() {
                this.dialogGroupVisible = true
                this.listLoadingGroup = true
                fetchGroupList(this.listQueryGroup).then(response => {
                    this.listGroup = response.data.list
                    this.totalGroup = response.data.total
                    this.listLoadingGroup = false
                }).catch((error)=>{
                    console.log(error)
                    this.listLoadingGroup = false
                })
            },
            getRoleList() {
                this.dialogRoleVisible = true
                this.listLoadingRole = true
                fetchRoleList(this.listQueryRole).then(response => {
                    this.listRole = response.data.list
                    this.totalRole = response.data.total
                    this.listLoadingRole = false
                }).catch((error)=>{
                    console.log(error)
                    this.listLoadingRole = false
                })
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleSizeChange(val) {
                this.listQuery.rows = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },

            handleSizeChangeGroup(val) {
                this.listQueryGroup.rows = val
                this.getList()
            },
            handleCurrentChangeGroup(val) {
                this.listQueryGroup.page = val
                this.getList()
            },

            handleSizeChangeRole(val) {
                this.listQueryRole.rows = val
                this.getList()
            },
            handleCurrentChangeRole(val) {
                this.listQueryRole.page = val
                this.getList()
            },

            handleCloseDialog() {
                this.resetForm()
            },
            handleFilter() {
                this.listQuery.page = 1
                this.getList()
            },
            handleFilterGroup() {
                this.listQueryGroup.page = 1
                this.getGroupList()
            },
            handleFilterRole() {
                this.listQueryRole.page = 1
                this.getRoleList()
            },
            handleResetFilter() {
                this.listQuery.companyId = undefined
                this.listQuery.departmentId = undefined
                this.$refs.filterForm.resetFields()
                this.getList()
            },
            handleVisibleShowOrg() {
                this.visibleShowOrg = !this.visibleShowOrg
                if(this.visibleShowOrg) {
                    this.userSpan = 18
                    this.getDataCompany()
                } else {
                    this.userSpan = 24
                }

            },
            handleCompanyNodeClick(data, node) {
                this.formCompany.id = data.id
                this.getDataDept(data.id)

                this.listQuery.companyId = data.id
                this.listQuery.departmentId = null
                this.getList()
            },
            handleDeptNodeClick(data, node) {
                this.formDept.id = data.id
                this.listQuery.departmentId = data.id
                this.getList()
            },

            handleCompanyNodeClickDialog(data, node) {
                this.selectCompanyId = data.id
                this.getDataDept(data.id)
            },
            handleDeptNodeClickDialog(data, node) {
                this.selectDeptId = data.id
                this.formDept.id = data.id
            },

            handleCreate() {
                this.dialogStatus = 'create'
                this.dialogFormVisible = true
            },
            handleUpdate(row) {
                this.dialogStatus = 'update'
                fetchObject(row.id).then(response => {
                    this.dialogFormVisible = true
                    this.form = Object.assign({}, response.data)
                })
            },
            handleDelete(row) {
                this.$confirm('确定要删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleted(row.id).then(response => {
                        if(response.data.status) {
                            this.$notify({
                                title: '成功', message: response.data.message,
                                type: 'success', duration: 2000
                            })
                            this.getList()
                        } else {
                            this.$notify({
                                title: '发生错误', message: response.data.message,
                                type: 'error', duration: 2000
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info', message: '已取消删除' })
                })
            },
            create() {
                this.$refs['form'].validate((valid) => {
                    if(valid) {
                        created(this.form).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })
                                this.getList()
                            } else {
                                this.$notify({
                                    title: '操作失败', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                            this.dialogFormVisible = false
                        })
                    }
                })
            },
            update() {
                this.$refs['form'].validate((valid) => {
                    if(valid) {
                        updated(this.form).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })
                                this.getList()
                            } else {
                                this.$notify({
                                    title: '发生错误', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                            this.dialogFormVisible = false
                        })
                    }
                })
            },
            handleResetPassword() {
                const ids = []
                for(var item of this.multipleSelection) {
                    ids.push(item.id)
                }
                if(ids != null && ids.length > 0) {
                    this.$confirm('确定要重置密码？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        batchResetPassword(ids).then((response) => {
                            if (response.data.status) {
                                this.$notify({
                                    title: '提示', message: '密码重置成功',
                                    type: 'success', duration: 2000
                                })
                                this.getList()
                            } else {
                                this.$notify({
                                    title: '提示', message: response.data.message,
                                    type: 'warning', duration: 2000
                                })
                            }
                        })
                    }).catch(() => {
                        this.$message({ type: 'info', message: '已取消删除' })
                    })
                } else {
                    this.$message({
                        message: '请选择需要重置密码的记录',
                        type: 'warning', duration: 2000
                    })
                }

            },
            handelUpdateStatus(status) {
                const ids = []
                for(var item of this.multipleSelection) {
                    ids.push(item.id)
                }
                if(ids != null && ids.length > 0) {
                    this.$confirm('确定要修改以下记录状态？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        batchUpdateStatus({"ids": ids, "status": status}).then((response) => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '提示', message: '密码重置成功',
                                    type: 'success', duration: 2000
                                })
                                this.getList()
                            } else {
                                this.$notify({
                                    title: '提示', message: response.data.message,
                                    type: 'warning', duration: 2000
                                })
                            }
                        })
                    }).catch(() => {
                        this.$message({ type: 'info', message: '已取消修改' })
                    })
                } else {
                    this.$message({
                        message: '请选择需要修改的记录',
                        type: 'warning', duration: 2000
                    })
                }

            },
            handleAddGroup() {
                if(this.multipleSelection.length > 0) {
                    this.getGroupList()
                } else {
                    this.$message({
                        message: '请选择需要加入组的用户',
                        type: 'warning', duration: 2000
                    })
                }

            },
            selectGroup(row, event, column) {
                this.selectGroupId = row.id
            },
            handelSaveAssignGroup() {
                if(this.selectGroupId) {
                    const ids = []
                    for(var item of this.multipleSelection) {
                        ids.push(item.id)
                    }
                    const assignData = {groupId: this.selectGroupId, userIds: ids}
                    addUserToGroupAssign(assignData).then(response => {
                        if(response.data.status) {
                            this.$notify({
                                title: '提示', message: '加入成功',
                                type: 'success', duration: 2000
                            })
                            this.dialogGroupVisible = false
                        } else {
                            this.$notify({
                                title: '提示', message: response.data.message,
                                type: 'warning', duration: 2000
                            })
                        }
                    })
                } else {
                    this.$message({
                        message: '请选择组',
                        type: 'warning', duration: 2000
                    })
                }
            },

            handleAddRole() {
                if(this.multipleSelection.length > 0) {
                    this.getRoleList()
                } else {
                    this.$message({
                        message: '请选择需要分配角色的用户',
                        type: 'warning', duration: 2000
                    })
                }

            },
            selectRole(row, event, column) {
                this.selectRoleId = row.id
            },
            handelSaveAssignRole() {
                if(this.selectRoleId) {
                    const ids = []
                    for(var item of this.multipleSelection) {
                        ids.push(item.id)
                    }
                    const assignData = {roleId: this.selectRoleId, userIds: ids}
                    addUserToRoleAssign(assignData).then(response => {
                        if(response.data.status) {
                            this.$notify({
                                title: '提示', message: '加入成功',
                                type: 'success', duration: 2000
                            })
                            this.dialogRoleVisible = false
                        } else {
                            this.$notify({
                                title: '提示', message: response.data.message,
                                type: 'warning', duration: 2000
                            })
                        }
                    })
                } else {
                    this.$message({
                        message: '请选择角色',
                        type: 'warning', duration: 2000
                    })
                }
            },

            handleAddOrganization() {
                if(this.multipleSelection.length > 0) {
                    this.selectCompanyId = undefined
                    this.selectDeptId = undefined
                    this.dialogOrganizationVisible = true
                    this.getDataCompany()
                } else {
                    this.$message({
                        message: '请选择需要加入组织机构的用户',
                        type: 'warning', duration: 2000
                    })
                }
            },
            handelSaveAssignOrganization() {
                if(this.selectCompanyId && this.selectDeptId) {
                    const ids = []
                    for(var item of this.multipleSelection) {
                        ids.push(item.id)
                    }
                    const assignData = {companyId: this.selectCompanyId, departmentId: this.selectDeptId, userIds: ids}
                    addUserToOrganizationAssign(assignData).then(response => {
                        if(response.data.status) {
                            this.$notify({
                                title: '提示', message: '加入组织机构成功',
                                type: 'success', duration: 2000
                            })
                            this.dialogOrganizationVisible = false
                        } else {
                            this.$notify({
                                title: '提示', message: response.data.message,
                                type: 'warning', duration: 2000
                            })
                        }
                    })
                } else {
                    this.$message({
                        message: '请选择公司和部门',
                        type: 'warning', duration: 2000
                    })
                }
            },
            command(command) {
                if(command === 'ResetPassword') {
                    this.handleResetPassword()
                } else if(command === 'AddGroup') {
                    this.handleAddGroup()
                } else if(command === 'AddOrganization') {
                    this.handleAddOrganization()
                } else if(command === 'AddRole') {
                    this.handleAddRole()
                } else if(command === 'SetStatusNormal') {
                    this.handelUpdateStatus(1)
                } else if(command === 'SetStatusForbidden') {
                    this.handelUpdateStatus(2)
                }
            },
            resetForm() {
                this.$refs['form'].resetFields()
                this.form = {
                    account: '',
                    realName: '',
                    sex: 1,
                    mobile: '',
                    email: '',
                    status: 1
                }
            }
        }
    }
</script>

<!-- 局部样式 -->
<style rel="stylesheet/scss" lang="scss" scoped>
    .card-header{
        border-bottom: 1px solid #d1dbe5; padding: 15px 20px 15px 7px;
    }
    .el-card__body{
        .el-tree{
            border: 0px;
        }
    }
</style>